#ifndef JSONCONFIGWRITER_H
#define JSONCONFIGWRITER_H

#include <QObject>
#include <QString>
#include <QStringList>
#include <QVariantMap>

class JsonConfigWriter : public QObject
{
    Q_OBJECT
public:
    explicit JsonConfigWriter(QObject *parent = nullptr,const QString &uiFilePath = QString());

    // 写入某个用户的控件配置；outputDir 为空则默认与 uiFilePath 同目录
    bool Write_To_Ui_Json(const QString &userRole,const QStringList &hiddenCtrls);

    // 读取指定用户的隐藏控件配置
    bool Read_Json_To_Ui(const QString &userRole,QStringList &hiddenCtrls) const;

    // 读取/写入 使用的用户
    bool readLastUser(QString &userRole) const;
    bool Write_To_User_Json(const QString &userRole);

    // 列出所有用户
    QVariantMap Read_Ui_UserMap(QVariantMap& Ui_JsonRoot)const;
    QStringList Match_Users_list() const;
    //从Ui.json中删除用户
    bool remove_User_From_Ui_Json(const QString &username);


    // 帮助函数：加载/保存 JSON
    bool load_Ui_JsonRootToMap(const QString &JsonPath, QVariantMap &Ui_JsonRoot) const;
    bool saveMapToJson(const QString &JsonPath, const QVariantMap &root) const;

    // 生成控件配置文件路径
    QString makeJsonPath() const;
    QString makeUsersPath() const;
private:
    QString m_uiFilePath;
};

#endif // JSONCONFIGWRITER_H
